package com.letoken.platform.repo.app.dao;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.letoken.platform.repo.admin.req.user.AdminBalanceHistoryListReq;
import com.letoken.platform.repo.admin.res.user.AdminBalanceHistoryRes;
import com.letoken.platform.repo.app.req.mall.BillingOutListReq;
import com.letoken.platform.repo.app.req.user.BalanceHistoryReq;
import com.letoken.platform.repo.app.res.mall.BillingStatisticsOutListRes;
import com.letoken.platform.repo.app.res.user.AppBalanceHistoryRes;
import com.letoken.platform.repo.mall.po.AppBalanceHistory;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.math.BigDecimal;
import java.time.LocalDateTime;

/**
 * <p>
 * 余币报资产 Mapper 接口
 * </p>
 *
 * @author author
 * @since 2023-07-25
 */
public interface AppBalanceHistoryMapper extends BaseMapper<AppBalanceHistory> {



    @Select("select IFNULL(sum(amount),0) from app_balance_history where  user_id = #{userId} and create_time >= #{startTime} and create_time < #{endTime} and  type = #{type}")
    BigDecimal incomeByTime(@Param("userId") Integer userId, @Param("startTime")LocalDateTime startTime,@Param("endTime") LocalDateTime endTime,@Param("type") Integer type);


    Page<AppBalanceHistoryRes> history(@Param("page") Page<AppBalanceHistoryRes> page , @Param("req") BalanceHistoryReq req);


    Page<AdminBalanceHistoryRes> adminHistory(@Param("page") Page<AdminBalanceHistoryRes> page , @Param("req") AdminBalanceHistoryListReq req);


    @Select("select sum(amount) from app_balance_history where create_time >= #{startTime} and create_time < #{endTime} and  type =  #{type} ")
    BigDecimal dayIncome(@Param("startTime")LocalDateTime startTime,@Param("endTime") LocalDateTime endTime,@Param("type") Integer type);


    @Select("select sum(amount) from app_balance_history where  type =  #{type}  and create_time >= '2023-10-12 15:00:00'")
    BigDecimal totalTransfer(@Param("type") Integer type);



    @Select("select 1 from app_balance_history where user_id = #{userId} and type = #{type}  and   DATE_FORMAT(create_time, '%Y-%m-%d') = DATE_FORMAT(NOW(), '%Y-%m-%d') limit 1")
    Integer isExitsCalculate(@Param("userId") Integer userId , @Param("type") Integer type);


}
